# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from jms.dws.dws_actual_taking_dt import jms_dws__dws_actual_taking_dt
from jms.dwd.oms.dwd_yl_oms_oms_order_incre_dt import jms_dwd__dwd_yl_oms_oms_order_incre_dt
from jms.dwd.tab import jms_dwd__dwd_barscan_send_dt
from jms.dwd.tab import jms_dwd__dwd_barscan_collect_dt
from jms.dim import jms_dim__dim_lmdm_sys_network_expand
from jms.dm.prescription.dm_prescription_reach_details_dt import jms_dm__dm_prescription_reach_details_dt
from jms.dwd.tab.dwd_tab_customer_monitor_deploy_dt import jms_dwd__dwd_tab_customer_monitor_deploy_dt
from jms.dwd.tab.dwd_tab_customer_monitor_vips_dt import jms_dwd__dwd_tab_customer_monitor_vips_dt
from jms.dim.dim_lmdm_sys_customer_addition import jms_dim__dim_lmdm_sys_customer_addition
#from jms.dwd.dwd_warhouse.dwd_wide_rank_basic_scaninfo_tms_dt import jms_dwd__dwd_wide_rank_basic_scaninfo_tms_dt_a15,jms_dwd__dwd_wide_rank_basic_scaninfo_tms_dt_b15
from jms.dwd.dwd_warhouse.dwd_wide_barscan_operations_hist_dt import jms_dwd__dwd_wide_barscan_operations_hist_dt

jms_dm__dm_customer_monitor_detail_dt = SparkSqlOperator(
    task_id='jms_dm__dm_customer_monitor_detail_dt',
    email=['guoruiling@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='dm_customer_monitor_detail_dt_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dm/dm_customer_monitor_detail_dt/execute.sql',
    driver_memory='4G',
    executor_memory='10G',
    executor_cores=6,
    num_executors=30,
    pool_slots=1,
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 50,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 120,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '4G',  # 堆外内存
          'spark.default.parallelism': 600,
          'spark.sql.shuffle.partitions': 600 ,
          'spark.shuffle.consolidateFiles': 'true',
          'spark.shuffle.memoryFraction': '0.8',
          'spark.shuffle.file.buffer':'64k',
          'spark.executor.extraJavaOptions': '-XX:+UseG1GC -XX:ParallelGCThreads=6',
          'spark.locality.wait.process':10   #默认3秒,
          #'spark.locality.wait':300 ,
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions.pernode': 200,
              'hive.exec.max.dynamic.partitions': 200
              },
    execution_timeout = timedelta(minutes=60),
)

jms_dm__dm_customer_monitor_detail_dt << [
    jms_dwd__dwd_yl_oms_oms_order_incre_dt,
    jms_dws__dws_actual_taking_dt,
    jms_dwd__dwd_barscan_send_dt,
    jms_dwd__dwd_barscan_collect_dt,
    jms_dim__dim_lmdm_sys_network_expand,
    jms_dm__dm_prescription_reach_details_dt,
    jms_dwd__dwd_tab_customer_monitor_deploy_dt,
    jms_dwd__dwd_tab_customer_monitor_vips_dt,
    jms_dim__dim_lmdm_sys_customer_addition,
    #jms_dwd__dwd_wide_rank_basic_scaninfo_tms_dt_a15,
    #jms_dwd__dwd_wide_rank_basic_scaninfo_tms_dt_b15
    jms_dwd__dwd_wide_barscan_operations_hist_dt
]
